import config from "./config.js"
export const request = function a(options) {
	{
		return new Promise((resolve, reject) => {
			// 在登录的时候需要储存 token uni.setStorageSync("authorization","这里是登录获取的token值")
			let token = ''
			if(uni.getStorageSync('openid')){
				token = uni.getStorageSync('openid');
			}
			uni.showLoading({
				title: '加载中...',
				 mask: true,
			});
			let out_time = 10000;
			if(options.url=='api/ser/config/get_gs'){
				out_time = 3000;
			}
			uni.request({
				url: config.baseUrl + options.url,
				data: options.data || {},
				method: options.method || 'POST',
				header: { "Token3": token },
				timeout:out_time,
				success: (res) => {
					// 控制台显示数据信息
					resolve(res.data)
					uni.hideLoading({
						fail() {}
					});
					if(res.data.code==1){
					}else{
						uni.showToast({
							icon: 'none',
							title: res.data.msg,
							duration: 2000,
						})
					}
				},
				fail: (err) => {
					uni.hideLoading();
					// 页面中弹框显示失败
					console.log('请求失败',err)
					// 返回错误消息
					reject(err)
				},
				catch: (e) => {
					console.log(e);
				}
			})
		})
	}
}
